//获取应用实例
const app = getApp();

Page({
  data: {
    accountId: '',//微信号
    phone: '',
    evaContent: '',
  },
  onLoad: function (options) {
  },

  accountInput: function (e) {
    var that = this;
    that.setData({
      accountId: e.detail.value
    })
  },

  phoneInput: function (e) {
    var that = this;
    that.setData({
      phone: e.detail.value
    })
  },

  charChange: function (e) {
    var that = this;
    that.setData({
      evaContent: e.detail.value
    })
  },

  //保存
  bindsavebank: function () {
    var that = this;
    if (that.data.accountId.length == 0) {
      wx.showToast({
        title: '请填写联系人',
        icon: 'none'
      })
      return;
    }
    if (that.data.phone.length == 0) {
      wx.showToast({
        title: '请选择联系方式',
        icon: 'none'
      })
      return;
    }
    if (that.data.evaContent.length == 0) {
      wx.showToast({
        title: '请填写申请原因',
        icon: 'none'
      })
      return;
    }
    wx.showLoading({
      title: '正在添加...',
    })
    wx.request({
      url: app.globalData.api + '/app.php?c=Message&a=online',
      data: {
        token: app.globalData.token,
        cat_id: 1,
        linkman: that.data.accountId,
        phone: that.data.phone,
        content: that.data.evaContent
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success(res) {
        console.log(res)
        wx.hideLoading();
        if (res.data.code == 0) {
          wx.showToast({
            title: '提交成功',//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'success', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })

          setTimeout(function () {
            //要延时执行的代码
            wx.navigateBack({
              delta: 1
            })
          }, 1000) //延迟时间 这里是1秒
        } else {
          wx.showToast({
            title: '' + res.data.msg,//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'none', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
        }

      }
    })
  },
});
